package com.xpffly.design.composite.demo.service.impl;

import com.xpffly.design.composite.demo.service.IBranch;
import com.xpffly.design.composite.demo.service.ILeaf;
import com.xpffly.design.composite.demo.service.IRoot;

import java.util.ArrayList;

/**
 * @Author: 午夜学徒
 * @Date: 2021/8/23 22:28
 * @Description：
 */
public class Root implements IRoot {
    /**
     * 保存根节点下的树枝节点和树叶节点，Subordinate是下级的意思
     */
    private ArrayList subordinate = new ArrayList();
    /**
     * 根节点名称
     */
    private String name;
    /**
     * 根节点职位
     */
    private String position;
    /**
     * 根节点薪水
     */
    private int salary = 0;

    public Root(String name, String position, int salary) {
        this.name = name;
        this.position = position;
        this.salary = salary;
    }

    public String getInfo() {
        String info = "";
        info = "名称：" + this.name;
        info += "\n职位：" + this.position;
        info += "\n薪水：" + this.salary;
        return info;
    }

    public void add(IBranch iBranch) {
        this.subordinate.add(iBranch);
    }

    public void add(ILeaf iLeaf) {
        this.subordinate.add(iLeaf);
    }

    public ArrayList getSubordinateInfo() {
        return this.subordinate;
    }
}
